{include file="public/layout" /}
<body>
  <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body web-system" pad15>
                <div class="layui-form" wid100 lay-filter="">
                  <div class="layui-form-item">
                    <label class="layui-form-label">导航位置</label>
                    <div class="layui-input-inline">
                        <div class="fl mr5" style="padding:6px 7px;">{$NavigList.position_name}</div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">所属菜单</label>
                    <div class="layui-input-inline">
                        {gt name="$hasChildren" value="0"}
                        <div class="fl mr5" style="padding:6px 7px;">{$select_html}</div>
                        <input type="hidden" name="parent_id" id="parent_id" value="{$NavigList.parent_id|default=''}" />
                        {else /}
                        <select id="parent_id" name="parent_id">
                            {$select_html}
                        </select>
                        {/gt}
                    </div>
                    <div class="layui-input-inline layui-btn-container {gt name="$hasChildren" value="0"} none {/gt}" style="width: auto;">
                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                      <div class="layui-form-inline2 ey_helptips_txt">如果选择上级菜单，那么新增的菜单则为被选择上级菜单的子菜单</div>
                    </div>
                  </div>
<!--                   <div class="layui-form-item">
                    <label class="layui-form-label">所属菜单</label>
                    <div class="layui-input-inline">
                        <select name="parent_id" lay-filter="parent_id">
                            <option value="0" data-grade="-1" {eq name="$NavigList.parent_id" value="0"} selected {/eq}>--默认顶级--</option>
                            {volist name="navig_select" id="vo"}
                                <option value="{$vo.navig_id}" data-grade="{$vo.grade}" {eq name="$NavigList.parent_id" value="$vo.navig_id"} selected {/eq}>{$vo.navig_name}</option>
                            {/volist}
                        </select>
                        <input type="hidden" name="grade" value="{$NavigList.grade|default=0}">
                    </div>
                  </div> -->
                  <div class="layui-form-item">
                    <label class="layui-form-label">快速生成菜单</label>
                    <div class="layui-input-inline w150">
                        <select lay-filter="FunctionData">
                            <option value="0" id="default" selected="true">功能页面</option>
                            {volist name="Function" id="vo"}
                                <option value="{$vo.code}" data-title="{$vo.title}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="layui-input-inline w30">
                        或者
                    </div>
                    <div class="layui-input-inline w200">
                        {$ArctypeHtml}
                    </div>
                    <div class="layui-input-inline w100">
                        <input type="checkbox" lay-skin="primary" name="arctype_sync" id="arctype_sync" lay-filter="arctype_sync" value="1" {eq name="$NavigList.arctype_sync" value="1"} checked="checked" {/eq} title="栏目同步">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>菜单名称</label>
                    <div class="layui-input-inline">
                     <input type="text" name="navig_name" id="navig_name" value="{$NavigList.navig_name}" lay-verify="required" class="layui-input" {eq name="$NavigList.arctype_sync" value="1"} readonly="readonly" style="background-color:#f5f5f5;" {/eq}>
                    </div>
                  </div>
                  <div class="layui-form-item {if condition="$NavigList.arctype_sync == 1 || empty($NavigList.type_id)"} none {/if}" id="dl_navig_url">
                    <label class="layui-form-label"><b>*</b>菜单链接</label>
                    <div class="layui-input-inline">
                     <input type="text" name="navig_url" id="navig_url" value="{$NavigList.navig_url}" lay-verify="required" class="layui-input" {eq name="$NavigList.arctype_sync" value="1"} readonly="readonly" style="background-color:#f5f5f5;" {/eq}>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">菜单副名</label>
                    <div class="layui-input-inline">
                     <input type="text" name="englist_name" value="{$NavigList.englist_name}" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                      <div class="layui-form-inline2 ey_helptips_txt">副名可用作栏目英文名、副标题等用途，若不用可不必填写</div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">菜单图标</label>
                    <div class="layui-input-inline">
                        <div class="upload-box">
                          <div class="upload-img fl">
                            <div class="icaction none">
                              <span class="load_images">
                                 <a href="javascript:void(0);" onclick="BigImages($('#img_navig_pic').attr('src'));">
                                 <i class="layui-icon layui-icon-search mr5"></i>查看
                                 </a>
                              </span>
                              <span class="load_images">
                                <a href="javascript:void(0);" data-inputid="navig_pic" onclick="DelImages(this);">
                                <i class="layui-icon layui-icon-delete mr5"></i>删除
                                </a>
                              </span>
                            </div>
                            <div class="cover-bg none"></div>
                            <img id="img_navig_pic" src="{$NavigList.navig_pic|get_default_pic=###}">
                          </div>
                          <div class="upload-right fl">
                            <button class="layui-btn test-upload-demoMore layui-btn-primary layui-btn-sm fl mb10 mr5" lay-data="{number:1,ey_inputId:'navig_pic',ey_savepath:'allimg'}"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                            <button class="layui-btn layui-btn-sm layui-btn-primary layui-btn-sm fl mb10" onClick="GetPictureFolder(1,'navig_pic');"><i class="layui-icon">&#xe64a;</i>图库</button>
                            <input name="navig_pic" id="navig_pic" placeholder="图片地址" value="{$NavigList.navig_pic|default=''}" class="layui-input">
                          </div>
                        </div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">链接属性</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" lay-skin="primary" name="target" value="1" {if condition="$NavigList.target == 1" }checked{/if} title="新窗口打开">
                        <input type="checkbox" lay-skin="primary" name="nofollow" value="1" {if condition="$NavigList.nofollow == 1" }checked{/if} title="nofollow">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="navig_id" value="{$NavigList.navig_id}">
                        <input type="hidden" name="position_id" value="{$NavigList.position_id}">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                    </div>
                  </div>
              </div>
            </div>
          </div>
        </div>
  </div>

  <script>

  $(document).ready(function(){
      // 鼠标事件，加载查看大图和删除图片
      $(".upload-img").live('mouseover', function(){
          $(this).find('div.icaction').show();
          $(this).find('div.cover-bg').show();
      }).live('mouseout', function(){
          $(this).find('div.icaction').hide();
          $(this).find('div.cover-bg').hide();
      });
  });

  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,form = layui.form;

    //所属菜单
    form.on('select(parent_id)', function(data){
        var value   = data.value;
        if (0 == value) {
            grade = 0;
        } else {
            var grade = $(data.elem).find("option:selected").attr('data-grade');
            grade = parseInt(grade) + 1;
        }
        $('input[name=grade]').val(grade);
    });

    //选中功能页面
    form.on('select(FunctionData)', function(data){
        var url   = data.value;
        var title = $(data.elem).find("option:selected").attr('data-title');
        if (url) $('#navig_url').val(url);
        if (title) $('#navig_name').val(title);
        $("#arctype_default").attr("selected", true);

        $('#arctype_sync').attr("checked", false);
        $('#navig_name').attr("readonly", false).css('background-color','');
        $('#navig_url').attr("readonly", false).css('background-color','');
        $('#dl_navig_url').hide();
        form.render();
    });

    //加载栏目信息
    form.on('select(type_id)', function(data){
        var obj = data.elem;
        var type_name = $(obj).find("option:selected").attr('data-typename');
        var type_url  = $(obj).find("option:selected").attr('data-typeurl');
        if (type_name) $('#navig_name').val(type_name);
        if (type_url) $('#navig_url').val(type_url);
        $("#default").attr("selected", true);
        $('#dl_navig_url').show();
        form.render();
    });

    // 同步栏目
    form.on('checkbox(arctype_sync)', function (data) {
        var obj = data.elem;
        var type_id = $('#type_id').val();
        if (type_id && type_id > 0) {
            if ($(obj).attr('checked')) {
                // 选中
                $('#navig_name').attr("readonly", true).css('background-color','#f5f5f5');
                $('#navig_url').attr("readonly", true).css('background-color','#f5f5f5');
                $('#dl_navig_url').hide();
            } else {
                // 取消选中
                $('#navig_name').attr("readonly", false).css('background-color','');
                $('#navig_url').attr("readonly", false).css('background-color','');
                $('#dl_navig_url').show();
            }
        } else {
            showErrorMsg('请先选择栏目');
            $(obj).attr("checked", false);
        }
        form.render();
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        var load = layer_loading();
        data.field._ajax = 1;
        $.ajax({
            type : 'post',
            url : "{:url('Navigation/edit')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        parent.gourl(res.url);
                    });
                }else{
                    showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });

  });

  </script>
{include file="public/footer" /}